<?php include_once __DIR__.'/../inc/userhead.html';?>
<?php include_once __DIR__.'/../inc/usermenu.html';?>
<div class="main_panel">
  <!--头部-->
  <div class="panel_head">
    <ul class="title">
      <li><a href="javascript:;">收货地址</a></li>
    </ul>
  </div>
  <!--头部-->
  <div style="height:25px"></div>
  <!--内容-->
  <div class="panel_form">
      <form name="addressForm" method="post" action="/user/saveAddr" class="layui-form">
      <p class="inl">
          <span>收货人姓名<em class="import">*</em></span>
          <input name="addressname" required lay-verify="required" type="text" placeholder="请输入收货人姓名" value="<?=isset($addrinfo['address_name'])?$addrinfo['address_name']:"";?>">
      </p>
      <p class="inl">
          <span>手机号码<em class="import">*</em></span>
          <input name="addresstel" required lay-verify="required" type="text" placeholder="请输入收货人手机号码" value="<?=isset($addrinfo['address_phone'])?$addrinfo['address_phone']:"";?>">
      </p>
      <p class="inl">
          <span>所在地区<em class="import">*</em>
          </span>
          <select name='province' lay-ignore>
              <option value=''>--省份--</option>
              <?php foreach($provincelist as $key => $value):?>
                <option value='<?=$value['id']?>' <?php $province = isset($addrinfo['province'])?$addrinfo['province']:""; if($value['id'] == $province):?>selected<?php endif;?>><?=$value['name']?></option>
              <?php endforeach;?>
          </select>
          <select name="city" lay-ignore>
              <option value=''>--选择城市--</option>
              <?php foreach($citylist as $key => $value):?>
                <option value='<?=$value['id']?>' <?php $province = isset($addrinfo['city'])?$addrinfo['city']:""; if($value['id'] == $city):?>selected<?php endif;?>><?=$value['name']?></option>
              <?php endforeach;?>
          </select>
          <select name="area" lay-ignore>
              <option value=''>--选择城市--</option>
              <?php foreach($districtlist as $key => $value):?>
                <option value='<?=$value['id']?>' <?php $province = isset($addrinfo['city'])?$addrinfo['city']:""; if($value['id'] == $district):?>selected<?php endif;?>><?=$value['name']?></option>
              <?php endforeach;?>
          </select>
      </p>
      <p class="inl">
          <span>详细地址<em class="import">*</em></span>
          <textarea name="addressmx" required lay-verify="required" placeholder="请输入正确的详细地址，方便快递员与您联系"><?=isset($addrinfo['address'])?$addrinfo['address']:"";?></textarea>
      </p>
      <p class="inl addMarg"><label>
          <input name="default" lay-ignore type="checkbox" class="defl" <?php $is_default = isset($addrinfo['is_default'])?$addrinfo['is_default']:""; if($is_default == 1):?>checked<?php endif;?> value="1">
          设为默认收货地址</label></p>
      <p class="inl addMarg"><a href="javascript:;" class="save_btn" lay-submit  lay-filter="myform">保存地址</a></p>
      <input name="addressid" type="hidden" value="<?=isset($addrinfo['id'])?$addrinfo['id']:"";?>">
      </form>
  </div>
  <!--内容-->
  <!--地址列表-->
  <div class="panel_addressList">
    <table>
      <tr class="head">
        <th>收货人</th>
        <th>手机号码</th>
        <th>详细地址</th>
        <th>操作</th>
        <th></th>
      </tr>
      <?php foreach($addrlist as $key => $value):?>
      <tr>
          <td width='100'>
              <?=$value['address_name']?>
              <?php if($value['is_default'] == 1):?><i class="hot">（默认）</i><?php endif;?>
          </td>
          <td width='100'><?=$value['address_phone']?></td>
          <td><?=$value['province']?>-<?=$value['city']?>-<?=$value['district']?>-<?=$value['address']?></td>
          <td width='100'>
              <a href='/user/useraddr?id=<?=$value['id']?>' >修改</a> |
              <a href='javascript:delUserAddress(<?=$value['id']?>);' class='key'>删除</a>
          </td>
      </tr>
        <?php endforeach;?>
    </table>
  </div>
  <!--地址列表-->
</div>
 <!--右面板-->
</div>
<script type='text/javascript'>
    region("addressForm","province","city","area");

    /******************选择省份，区域，城市*****************/
    function region(FormName,Formprovince,Formcity,Formarea){
        var province = eval('document.' + FormName + "." + Formprovince);
        var city = eval('document.' + FormName + "." + Formcity);
        var area = eval('document.' + FormName + "." + Formarea);
    	//根据省份返回城市
    	province.onchange = function(){
    	    area.innerHTML = "<option value=''>--区域--</option>";
    		$.post("/Publics/getComAddress",{pid:this.value},function(data){
                var areadata = data.data;
                var html = "<option value=''>--城市--</option>";
                for(var i=0;i<areadata.length;i++){
                    html += "<option value='" + areadata[i].id + "'>" + areadata[i].name + "</option>";
                }
    		    city.innerHTML = html;
    		},"json");
    	}
    	//根据省份返回城市
    	city.onchange = function(){
    	    $.post("/Publics/getComAddress",{pid:this.value},function(data){
                var areadata = data.data;
                var html = "<option value=''>--区域--</option>";
                for(var i=0;i<areadata.length;i++){
                    html += "<option value='" + areadata[i].id + "'>" + areadata[i].name + "</option>";
                }
    		    area.innerHTML = html;
    		},"json");
    	}
    }

    //删除地址
    function delUserAddress(id){
        layer.confirm("确定要删除该数据？",function(){
            $.post("/user/delUserAddress",{id:id},function(data){
                if(data.code==0){
                    layer.msg(data.msg);
                    window.location.reload();
                }else{
                    layer.msg(data.msg);
                }
            },"json");
        });
    }
</script>
<?php include_once __DIR__.'/../inc/foot.html';?>
